﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="dokumentType", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DokumentType))]
    public class DokumentTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDokumentType clazz;
        
        public DokumentTypeSerializer(IDokumentType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("id");
            if (clazz.Id!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Id))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Id");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("failinimi");
            if (clazz.Failinimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Failinimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Failinimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("keel");
            if (clazz.Keel!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Keel))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Keel");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumentType>id");
                }
                clazz.Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>dokumentType>id", Reader.LocalName);
            }
            if (Reader.LocalName=="failinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumentType>failinimi");
                }
                clazz.Failinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("failinimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>dokumentType>failinimi", Reader.LocalName);
            }
            if (Reader.LocalName=="keel") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>dokumentType>keel");
                }
                clazz.Keel = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("keel")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>dokumentType>keel", Reader.LocalName);
            }
        }
    }
}
